!function (t) {
    function i(s) {
        if (e[s]) return e[s].exports;
        var n = e[s] = {
            exports: {},
            id: s,
            loaded: !1
        };
        return t[s].call(n.exports, n, n.exports, i), n.loaded = !0, n.exports
    }
    var e = {};
    return i.m = t, i.c = e, i.p = "./", i(0)
}([function (t, i, e) {
    e(1),e(2),e(3)
},  function (t, i) {
    Vue.component("pop-user-capital-adjusted-component", {
        template:'<div class="pop-panel" v-bind:class="{\'show\':this.show}"><div class="pop-box"><div class="pop-title">{{title}}<a class="win_close_btn" @click="close()"><i class="fa fa-fw fa-close"></i></a></div><div class="pop-content"><validator name="validatorMethod"><form role="form"><div class="box-body"><div class="form-group"><label for="color">操作金额</label><input type="text" id="user.balance" @invalid="balanceInvalid" detect-change="off" detect-blur="off" initial="off" v-model="user.balance" class="form-control" v-validate:balance="{min:0}"></div><div class="form-group"><label for="color">备注</label><textarea id="user.remark" v-model="user.remark" class="form-control" ></textarea></div></div><div class="box-footer"><button type="button" class="btn btn-info btn-sm" style="width:120px;float:left;" @click="save()">{{button}}</button><button type="button" class="btn  btn-default btn-sm" style="width:120px;float:left;margin-left:15px;" @click="close()">取消</button></div></form></validator></div></div><div class="bg"></div></div>',
        data: function () {
            return {
                show: !1,
                title:'提示窗口',
                button:'',
                showError:null,
                user: null
            }
        },
        events: {
            'openUserCapitalAdjustedWin': function (t) {
                var i = this;
                i.data_init(t);
            },
        },
        methods: {
            data_init: function (t) {
                var title = "";
                var button = '确认';
                if (t.type == 1) {
                    title = "操作金额-增加用户余额";
                    button = '确认增加';
                } else {
                    title = "操作金额-扣除用户余额";
                    button = '确认扣除';
                }
                this.title = title, this.button = button, this.user = t, this.showError = [], this.show = !0;
            },
            balanceInvalid:function() {
                var t = this;
                t.showError.push("金额填写不正确");
            },
            save: function() {
                var t = this;
                t.$validate(true,function () {
                    if(!t.$validatorMethod.invalid) {
                        var index = layer.load(0, {shade:[0.3, '#000000']}); //0代表加载的风格，支持0-2
                        postMsg(root+"/user/capital_adjuste", t.user, function(i) {
                            layer.close(index);
                            layer.alert(i.msg);
                            if (i.code == 0) {
                                t.show = !1;
                                var key = "balance";
                                t.$dispatch("refreshUser", {key:key,value:i.money});
                            }
                        });
                    } else {
                        layer.alert(t.showError[(t.showError.length-1)], {end:function () {
                            t.showError = [];
                        }});
                    }
                });
            },
            close: function () {
                var t = this;
                t.show = !1;
            }
        }
    })
},  function (t, i) {
    Vue.component("pop-tree-organization-component", {
        template:'<div class="pop-panel" v-bind:class="{\'show\':this.show}"><div class="pop-box"><div class="pop-title">选择机构<a class="win_close_btn" @click="close()"><i class="fa fa-fw fa-close"></i></a></div><div class="pop-content"><div style="height:435px;width:100%;overflow-y:scroll;overflow-x:auto;"><ul id="treeDemo" class="ztree"></ul></div><div class="box-footer"><button type="button" class="btn btn-info btn-sm" @click="selectOrg()" style="width:120px;float:left;">{{button}}</button><button type="button" class="btn  btn-default btn-sm" style="width:120px;float:left;margin-left:15px;" @click="close()">取消</button></div></div></div><div class="bg"></div></div>',
        data: function () {
            return {
                show: !1,
                title:'选择机构',
                button:'确认选择',
                selectNodes:[],
            }
        },
        events: {
            'openTreeOrganizationWin': function () {
                var i = this;
                i.data_init();
            },
        },
        methods: {
            data_init: function () {
                this.selectNodes=[],this.show = !0;
                this.getTree();
            },
            getTree:function () {
                var t = this;
                postMsg(root+"/organization/tree", {s:true}, function(i) {
                    var setting = {
                        callback:{
                            onClick:function (event, treeId, treeNode, clickFlag) {
                                tree.checkNode(treeNode, clickFlag, clickFlag);
                            },
                            onCheck:function (event, treeId, treeNode) {
                                // console.log(treeNode.checked);
                                if (treeNode.checked == true) {
                                    t.selectNodes.push(treeNode);
                                } else {
                                    for (var i = 0; i<t.selectNodes.length; i++) {
                                        if (t.selectNodes[i].id == treeNode.id) {
                                            t.selectNodes.splice(i, 1);
                                        }
                                    }
                                }
                            }
                        },
                        check: {
                            enable: true,
                            chkboxType:{ "Y":"", "N":""},
                            chkStyle: "checkbox"
                        }
                    };
                    var tree = $.fn.zTree.init($("#treeDemo"), setting, i);
                });
            },
            selectOrg:function () {
                var t = this;
                if (t.selectNodes.length == 0) {
                    layer.alert('请选择一个机构');
                } else {
                    // console.log(t.selectNodes);
                    var organization_ids = "";
                    var organization_names = "";
                    for (var i=0; i<t.selectNodes.length; i++) {
                        var node = t.selectNodes[i];
                        // organization_ids.push(node.id);

                        if (organization_ids != "") {
                            organization_ids += ",";
                        }
                        organization_ids += node.id;


                        if (organization_names != "") {
                            organization_names += ",";
                        }
                        organization_names += node.name;
                    }
                    t.$dispatch("selectOrg", {organization_ids:organization_ids, organization_names:organization_names});
                    t.close();
                }
            },
            close: function () {
                var t = this;
                t.show = !1;
            }
        }
    })
},  function (t, i) {
    Vue.component("pop-belong-tree-organization-component", {
        template:'<div class="pop-panel" v-bind:class="{\'show\':this.show}"><div class="pop-box" style="width: 275px;"><div class="pop-title">{{title}}<a class="win_close_btn" @click="close()"><i class="fa fa-fw fa-close"></i></a></div><div class="pop-content"><div style="height:250px;padding:10px;overflow-y:scroll;overflow-x:auto;"><label>所属机构</label><ul id="treeBelongDemo" class="ztree"></ul></div><div class="form-group" style="padding:10px;"><label>所属经纪人</label><select class="form-control" id="agent_arr" style="width:100%" v-bind:value="selectAgentId" v-model="selectAgentId"><option value="0">选择经纪人</option><option v-for="agent in agent_arr" value="{{agent.id}}">{{agent.name}}</option></select></div><div class="box-footer"><button type="button" class="btn btn-info btn-sm" @click="selectOrg()" style="width:120px;float:left;" v-bind:disabled="isDisabled">{{button}}</button><button type="button" class="btn  btn-default btn-sm" style="width:120px;float:left;margin-left:15px;" @click="close()">取消</button></div></div></div><div class="bg"></div></div>',
        data: function () {
            return {
                show: !1,
                title:'客户归属',
                button:'确认选择',
                selectNode:null,
                selectAgentId:0,
                oldNode:null,
                oldAgentId:0,
                user:null,
                isDisabled:!1,
                agent_arr:[]
            }
        },
        events: {
            'openBelongTreeOrganizationWin': function (t) {
                var i = this;
                i.data_init(t);
            },
        },
        methods: {
            data_init: function (t) {
                this.selectNodes=[],this.user=t.user;
                this.getTree();
            },
            getTree:function () {
                var t = this;
                postMsg(root+"/organization/tree2", {agent_id:t.user.id,user_type:2}, function(i) {
                    var setting = {
                        callback:{
                            /*beforeClick: function (treeId, treeNode) {
                                return (treeNode.isP === 1);
                            },*/
                            onClick:function (event, treeId, treeNode, clickFlag) {
                                if (clickFlag == 1) {
                                    t.selectNode = treeNode;
                                    // t.isDisabled = !1;
                                    t.loadAgentList();
                                } else {
                                    t.selectNode = null;
                                    // t.isDisabled = 0;
                                }
                            }
                        }
                    };
                    var treeObj = $.fn.zTree.init($("#treeBelongDemo"), setting, i);
                    var nodes = treeObj.getNodes();
                    t.ergodicTree(nodes, treeObj);
                    t.loadAgentList();
                });
            },
            loadAgentList:function () {
                var t = this;
                t.agent_arr = [];
                var org_id = 0;
                if (t.selectNode != null) {
                    org_id = t.selectNode.id;
                }
                postMsg(root+"/agent/toSelectList", {organization_id:org_id, user_id:t.user.id}, function(i) {
                    t.agent_arr = i.list;
                    t.selectAgentId = t.user.recommend_id;
                    t.oldAgentId = t.user.recommend_id;
                });
            },
            ergodicTree:function (nodes, treeObj) {
                if (nodes.length>0) {
                    for (var i = 0; i<nodes.length; i++) {
                        if (nodes[i].selected == true) {
                            treeObj.selectNode(nodes[i]);
                            this.oldNode = nodes[i];
                            treeObj.setting.callback.onClick(null, treeObj.setting.treeId, nodes[i], true);//触发函数
                        }
                        if (nodes[i].children !== undefined) {
                            this.ergodicTree(nodes[i].children, treeObj);
                        }
                    }
                }
                this.show = !0;
            },
            selectOrg:function () {
                var t = this;
                if (t.selectNode == null) {
                    layer.alert('请选择一个机构');
                } else {


                    if((t.oldNode != null && t.oldNode.id == t.selectNode.id) && (t.oldAgentId != 0 && t.selectAgentId == t.oldAgentId)) {
                        t.close();
                    } else {
                        var agent_name = "";
                        var agent_name_txt = "--";
                        if (t.selectAgentId > 0) {
                            agent_name = "-" +  $("#agent_arr").find("option:selected").text() + "";
                            agent_name_txt = $("#agent_arr").find("option:selected").text();
                        }

                        layer.confirm('确定要将该客户移动到“'+t.selectNode.name + agent_name +'”下吗？', {
                            btn: ['确定','取消'] //按钮
                            ,closeBtn: 0
                        }, function(index){
                            layer.close(index);
                            var org_level = t.selectNode.org_level;
                            var org_id = t.selectNode.id;
                            var user_id = t.user.id;
                            postMsg(root+"/user/changeBelong", {org_level:org_level, org_id:org_id, agent_id:t.selectAgentId, user_id:user_id}, function(i) {
                                if (i.code == 1) {
                                    layer.alert("客户归属已转换", {end:function () {
                                        t.user.micro_ring = t.selectNode.name;
                                        t.user.agent_name = agent_name_txt;
                                        t.close();
                                    }});
                                } else {
                                    layer.alert("经纪人归属转换失败");
                                }
                            });

                        });
                    }
                }
            },
            close: function () {
                var t = this;
                t.show = !1;
                // t.isDisabled = 0;
                t.selectNode = null;
                t.oldNode=null;
                t.agent=null;
            }
        }
    })
}]);